<!DOCTYPE html "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">


<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">渠道名称：</label>
                            <div class="col-sm-10">
                                <input id="channelName" name="channelName"
                                       class="form-control" type="text" maxlength="50">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">渠道标识代码：</label>
                            <div class="col-sm-10">
                                <input id="channelCode" name="channelCode"  tabindex="2" class="form-control" type="text" maxlength="15">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">渠道用户编号：</label>
                            <div class="col-sm-10">
                                <input id="channelUserId" name="channelUserId" tabindex="2" class="form-control" type="text" maxlength="15">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">扣减比例：</label>
                            <div class="col-sm-10">
                                <input id="deductRate" name="deductRate" tabindex="2" class="form-control" type="text" maxlength="8">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属应用编号：</label>
                            <div class="col-sm-10">
                                <select name="appId" id="appId"  >
                                    <option value="">--请选择所属应用--</option>
                                    <option th:each="appinfo,userStat:${appInfos}" th:value="${appinfo.appId}" th:text="${appinfo.appName}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">马甲开关:</label>
                            <div class="col-sm-10">
                                <label class="radio-inline">
                                    <input type="radio" name="loanSwitch" value="1" /> 开
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="loanSwitch" value="0" /> 关
                                </label>
                            </div>
                        </div>

                        <div class="text-right form-group">
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    $().ready(function () {
        validateRule();

        // $('.summernote').summernote({
        //     height: '220px',
        //     lang: 'zh-CN',
        //     callbacks: {
        //         onImageUpload: function (files, editor, $editable) {
        //             sendFile(files);
        //         }
        //     }
        // });
    });
    $("#deductRate").on("input", function (evt) {
        var self = $(this);
        self.val(self.val().replace(/[^0-9\.]/g, ''));
        if ((evt.which != 46 || self.val().indexOf('.') != -1) && (evt.which < 48 || evt.which > 57)) {
            evt.preventDefault();
        }
    });

    $.validator.setDefaults({
        submitHandler: function () {
            save();
        }
    });


    function save() {
        //var content_sn = $("#content_sn").summernote('code');
        //$("#productDetail").val(content_sn);
        $.ajax({
            cache: true,
            type: "POST",
            url: "/app/channel/save",
            data: $('#signupForm').serialize(), // 你的formid
            async: false,
            success: function (data) {
                layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
            }
        });
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                channelName: {
                    required: true,
                    remote : {
                        url : "/app/channel/channelNameCodeExit", // 后台处理程序
                        type : "post", // 数据发送方式
                        dataType : "json", // 接受数据格式
                        data : { // 要传递的数据
                            channelName : function() {
                                return  $.trim($("#channelName").val());
                            }
                        }
                    }
                },
                channelCode:{
                    required: true,
                    remote : {
                        url : "/app/channel/channelNameCodeExit", // 后台处理程序
                        type : "post", // 数据发送方式
                        dataType : "json", // 接受数据格式
                        data : { // 要传递的数据
                            channelCode : function() {
                                return $.trim($("#channelCode").val());
                            }
                        }
                    }
                },
                channelUserId:{
                    required: true

                },
                deductRate:{
                    required: true

                },
                appId:{
                    required: true
                }
            },
            messages: {
                channelName: {
                    required: icon + "必填",
                    remote : icon + "渠道名称已存在"
                },
                channelCode: {
                    required: icon + "必填",
                    remote : icon + "渠道标识代码已存在"
                },
                channelUserId: {
                    required: icon + "必填"
                },
                deductRate: {
                    required: icon + "必填"
                },
                appId: {
                    required: icon + "必填"
                }
            }
        })
    }

</script>
</body>
</html>